package pub.cleangao.memm.transport.netty.compress;

import lombok.extern.slf4j.Slf4j;
import org.xerial.snappy.Snappy;

import java.io.IOException;


@Slf4j
public class SnappyCompress implements Compress {

    @Override
    public byte[] compress(byte[] bytes) {
        try {
            return Snappy.compress(bytes);
        } catch (IOException e) {
            throw new RuntimeException("snappy compress error", e);
        }
    }

    @Override
    public byte[] decompress(byte[] bytes) {
        try {
            return Snappy.uncompress(bytes);
        } catch (IOException e) {
            throw new RuntimeException("snappy decompress error", e);
        }
    }

    @Override
    public String type() {
        return CompressType.SNAPPY.getName();
    }


}
